<?php
class clsOptions
{
	static public function options_array($arr, $selectedItem)
	{
		$strOption = "";
		while (list($key, $value) = each($arr))
		{
		  $checked = (string)$selectedItem == (string)$key ||  (string)$selectedItem == (string)$value ? " selected=\"selected\"" : "";
		  $strOption .="<option title='". $value ."' value=\"" . $key . "\"" . $checked . ">" . $value . "</option>";
		}
		return $strOption;
	}
	static public function option_image($ctr_id, $arr, $selected = "")
	{
		$strOption = "";
		$i = 0;
		$strOption .= '<table border="0" cellpadding="0" cellspacing="0">';
		while(list($key, $value) = each($arr))
		{
			$imgName = "images/radio_unchecked.jpg";
			if($selected != "" && $selected == $key)
				$imgName = "images/radio_checked.jpg";
				
			$strOption .= "<tr><td><img name='img_$ctr_id' id='$key' onclick=\"change_option_image(this, '$ctr_id')\" src='$imgName' border='0' style=\"cursor:pointer; \"></td><td width=4></td><td class=radio>$value</td></tr><tr><td height=5></td></tr>";
	
			$i++;
		}
		$strOption .= '</table>';
		$strOption .= "<input type=\"hidden\" name=\"$ctr_id\" id=\"$ctr_id\" value=\"$selected\" />\n";
		return $strOption;
	}
	static public function options_multiple($stSQL)
	{
			$rows = $GLOBALS["db_mysql"]->query($stSQL);			
			$strOption = "";
			if($GLOBALS["db_mysql"]->affected_rows > 0)
			{
			   while ($row = $GLOBALS["db_mysql"]->fetch_array($rows))
			   {
				  $valueOpt = $row["No"];
				  $strOption .="<option title='". $row["Name"] ."' value=\"" . $valueOpt . "\"" . ">" . $row["Name"] . "</option>";			  
			   }
			}
			return $strOption;
	}
	static public function options($stSQL, $selectedItem, $defaultText = "", $defaultValue = "")
	{
			$rows = $GLOBALS["db_mysql"]->query($stSQL);			
			$strOption = "<option value=\"" . $defaultValue . "\">" . $defaultText . "</option>";
			if($GLOBALS["db_mysql"]->affected_rows > 0)
			{
			   while ($row = $GLOBALS["db_mysql"]->fetch_array($rows))
			   {
				  $valueOpt = $row["No"];
				  
				  $checked = ($selectedItem == $valueOpt ||  $selectedItem == $row["Name"]) ? " selected=\"selected\"" : "";
				  $strOption .="<option title='". $row["Name"] ."' value=\"" . $valueOpt . "\"" . $checked . ">" . $row["Name"] . "</option>";			  
			   }
			}
			return $strOption;
	}
	static public function optionsGroupsAndCategories($stSQL, $strsqlCate, $selectedItem)
	{
		$db_mysql = new db_mysql;
		$db_mysql->connect();
		$rows = $db_mysql->query($stSQL);	
		$strOption = "<option value=\"\">--Select-</option>";
		if($db_mysql->affected_rows > 0)
		{
		   while ($row = $db_mysql->fetch_array($rows))	
		   {
			  $strOption .="<option style=\"color:#FF0000;background-color:#66CCFF\" value=\"" . "\">" . $row["Name"]."</option>";
			  $sqlCate = $strsqlCate . $row["No"]; 
			  $resultCate = $db_mysql->query($sqlCate);	
			  if($db_mysql->affected_rows > 0)
			  {
				while ($row = $db_mysql->fetch_array($resultCate))
				{
				  $valueOpt = $row["No"];
				  $checked = $selectedItem == $valueOpt ? " selected=\"selected\"" : "";					  	
				  $strOption .="<option value=\"" . $valueOpt . "\"" . $checked . ">&nbsp;&nbsp;&nbsp;" . $row["Name"] . "</option>";					  
				 }
			  }
		   }
		}
		return $strOption;
	}
	static public function option_timehr($selected = "")
	{
		$arr = array('00'=>'00', '01'=>'01', '02'=>'02', '03'=>'03', '04'=>'04', '05'=>'05', '06'=>'06', '07'=>'07', '08'=>'08', '09'=>'09', '10'=>'10', '11'=>'11', '12'=>'12', '13'=>'13', '14'=>'14', '15'=>'15', '16'=>'16', '17'=>'17', '18'=>'18', '19'=>'19', '20'=>'20', '21'=>'21', '22'=>'22', '23'=>'23');
		$strOption = "";
		while(list($key, $value) = each($arr))
		{
			$checked = $selected != "" && $selected==$key ? " selected='selected'" : "";
			$strOption .= "<option title='".$value."' value=\"" ;
			$strOption .= $key . "\"" . $checked . ">";
			$strOption .= $value."</option>";		
		}
		return $strOption;
	}
	static public function option_timemin($selected = "")
	{
		$arr = array('00'=>'00', '05'=>'05', '10'=>'10', '15'=>'15', '20'=>'20', '25'=>'25', '30'=>'30', '35'=>'35', '40'=>'40', '45'=>'45', '50'=>'50', '55'=>'55');
		$strOption = "";
		while(list($key, $value) = each($arr))
		{
			$checked = $selected != "" && $selected==$key ? " selected='selected'" : "";
			$strOption .= "<option title='".$value."' value=\"" ;
			$strOption .= $key . "\"" . $checked . ">";
			$strOption .= $value."</option>";		
		}
		return $strOption;
	}
}
?>
